package com.lpx.blog.validator;

import com.lpx.blog.dto.UserLoginDTO;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.lang.annotation.Annotation;

/**
 * @Author: ColorSheep
 * @Description: TODO
 * @Date: 2024/11/21 13:54
 * @Version: 1.0
 */
public class UsernameOrEmailValidator implements ConstraintValidator {
	@Override
	public void initialize(Annotation constraintAnnotation) {
		ConstraintValidator.super.initialize(constraintAnnotation);
	}

	@Override
	public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
		UserLoginDTO userLoginDTO = (UserLoginDTO) o;
		return (userLoginDTO.getUsername() != null && !userLoginDTO.getUsername().isEmpty()) ||
				(userLoginDTO.getEmail() != null && !userLoginDTO.getEmail().isEmpty());
	}
}
